<?php
	include('conn.php');
	date_default_timezone_set("Asia/Chongqing");
	$_GUID = $_POST['guid'];
	$_targetfile = __TEMPLATE__.'dswave.user.js';
	if ($_POST){
		if (!$_GUID){die('Invalid serial number');}
		//0806-d722f447-eeb6-47d0-af50-7dccc226a511-0809
		//在GUID上加入用户类型，按不懂的用户类型，进入不同的目录里取文件，生成不同的功能
		//查到status=0的记录，正确时将卡status改为1，为已用
		$sql = "select * from List_Card Where CardID='$_GUID'";
		$result = $db->row_query_one($sql);
		if($result){
			$rule = explode("-",$result['CardID']);
			$current_date = date("ym",time());
			if(count($rule)!=7){die('serial number of rules error');}
			if($rule[6]<$current_date){
				die('serial number has expired');
			}else{
				if ($result['Status']==0){
					$overdue = time()+(24*60*60*$rule[1]);
					$sUpdate = "update List_Card set Status=1,Active='".time()."',overdue='".$overdue."' Where CardID='".$_GUID."'";
					$db->query($sUpdate);
				}
				$uesrtype = "dswave_tw_0303";
				$html_js = file_get_contents($_targetfile);
				$html_js = str_replace('$__GUID__$',$result['CardID'],$html_js);
				$html_js = str_replace('$__VIRTUALPATH__$',__VIRTUALPATH__,$html_js);
				//header('Content-type: text/javascript');
				//echo $html_js;
				$_NewFile = $_GUID.".user.js";
				file_put_contents("".__ABSPATH__."tmp/".$_NewFile,$html_js);
				//header("Location:http://www.qilongjitools.cn/dswave_verify/tmp/".$_NewFile);
				//echo "<script>window.open('http://www.qilongjitools.cn/dswave_verify/tmp/".$_NewFile."');</script>";
				echo("驗證成功,<a href='".__VIRTUALPATH__."tmp/".$_NewFile."'>點擊本鏈接安裝最新腳本</a>");
				exit();
			}
		}else{
			die('Invalid serial number');
		}
	}
?>
<form name="form1" method="post" action="" onsubmit="if(document.getElementById('guid').value==''){alert('驗證碼不能為空');retrun false;}else{return true;}">
	<table>
		<tr>
			<td><input name="guid" id="guid"></td><td><input type="submit" value="驗證"></td>
		</tr>
	</table>
	<table>
		<tr>
			<td>屠龍者-免費試用15天版本，無需驗證，<a href='<?php echo __VIRTUALPATH__?>tmp/Freekeydswave.user.js'>點此安裝</a>。(腳本到期時間2009-4-4)</td>
		</tr>
	</table>
</form>